package gdut.imis.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import gdut.imis.Utils.Result;
import gdut.imis.domain.ExamInfo;
import gdut.imis.enums.Status;
import gdut.imis.mapper.ExamInfoMapper;
import gdut.imis.service.ExamInfoService;
import gdut.imis.vo.ExamInfoVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description
 * @Author JiaFu
 * @Date 2023/4/7 21:44
 */
@Service
@RequiredArgsConstructor
public class ExamInfoServiceImpl extends ServiceImpl<ExamInfoMapper, ExamInfo> implements ExamInfoService {

    private final ExamInfoMapper examInfoMapper;
    /***
     * 新增考试信息档案
     * @param: examInfo
     * @return Result
     */
    @Override
    public Result addExamInfo(ExamInfo examInfo) {
        if (Objects.isNull(examInfo)) {
            return Result.errorWithArgs(Status.REQUEST_PARAMS_NOT_VALID_ERROR, "examInfo");
        }
        boolean flag = this.save(examInfo);
        if (flag) {
            return Result.success();
        }
        return Result.errorWithArgs(Status.FAILED, "新增考试信息档案失败");
    }

    /***
     * 根据学生id获取学生第一次考试的档案回忆
     * @param: studentId
     * @return Result
     */
    @Override
    public Result getExamMemoryBystuId(Long studentId) {
        ExamInfoVo examInfoVo = examInfoMapper.getExamMemoryBystuId(studentId);
        if (Objects.isNull(examInfoVo)) {
            return Result.errorWithArgs(Status.FAILED,"没有查询到该学生的考试档案回忆");
        }
        return Result.success(examInfoVo);
    }
}
